#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/4/11 16:44
# @Author  : zzp
# @File    : ViewWorker
# @Software: PyCharm
import subprocess

from PyQt5.QtCore import QThread, pyqtSignal


class ViewWorker(QThread):
    output_signal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.cmd = 'tensorboard --logdir runs'

    def run(self):
        try:
            self.output_signal.emit(self.cmd)
            self.proc = subprocess.Popen(
                self.cmd,
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )
            self.output_signal.emit(f'以执行命令：{self.cmd}，请用浏览器打开http://localhost:6006/')
        except Exception as e:
            self.output_signal.emit(f"[异常] 执行命令时发生错误：{str(e)}")
